package mvc.helix;

import gui.Block;
import gui.CheckboxPanel;
import gui.SliderPanel;

import java.awt.Dimension;
import java.awt.GridBagConstraints;

import javax.swing.BoxLayout;
import javax.swing.JPanel;

import mvc.ControllerMouse3D;
import mvc.CurveView3D;
import mvc.MouseController2D;
import mvc.ViewCurve2D;

import org.geom.render.Engine2D;

public class HelixBlock extends Block {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	HelixModel curve;
	
	public HelixBlock(String title, HelixModel model) {
		super(title);
		this.curve = model;
		
		initSwing(model);
	}

	@Override
	protected void initControls() {
		super.initControls();
		
		JPanel p = new JPanel();
		p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
		
		HelixPanelController controller = new HelixPanelController((HelixModel) curve);
		
		CheckboxPanel c = new CheckboxPanel("Curve Points",controller, "CurvePoints");
		controller.setCurvePoint(true);
		p.add(c);
		
		SliderPanel s = new SliderPanel("Radius", 0, 100, 20, controller, "R");
		controller.setR(20);
		p.add(s);

		s = new SliderPanel("Spiral space", 0, 100, 20, controller, "K");
		controller.setK(20);
		p.add(s);
		
		s = new SliderPanel("Max param value", 0, 1000, 80, controller, "MAXT");
		controller.setMAXT(80);
		p.add(s);
		
		controlWindow.add(p);
		controlWindow.setLocation(1000, 10);
		
	}
	
	private void initSwing(HelixModel helix) {
		ViewCurve2D view2d;
		CurveView3D view3d;
		MouseController2D controller2d;
		ControllerMouse3D controller3d;
		
		Dimension dim = new Dimension(380,300);
		
		GridBagConstraints c = new GridBagConstraints();
		c.gridx = 0;
		c.gridy = 0;
		c.weightx = 10;
		c.weighty = 10;
		view2d = new ViewCurve2D(helix, Engine2D.X, dim);
		helix.addView(view2d);
		controller2d = new MouseController2D(helix, Engine2D.X, view2d);
		view2d.addMouseController(controller2d);
		//view2d.setTranslate(new Point3D(50, 100, 0));
		addView(view2d, c);
		
		c = new GridBagConstraints();
		c.gridx = 0;
		c.gridy = 1;
		c.weightx = 10;
		c.weighty = 10;
		view2d = new ViewCurve2D(helix, Engine2D.Y, dim);
		controller2d = new MouseController2D(helix, Engine2D.Y, view2d);
		helix.addView(view2d);
		view2d.addMouseController(controller2d);
		//view2d.setTranslate(new Point3D(50, 100, 0));
		addView(view2d, c);

		c = new GridBagConstraints();
		c.gridx = 1;
		c.gridy = 0;
		c.weightx = 10;
		c.weighty = 10;
		view2d = new ViewCurve2D(helix, Engine2D.Z, dim);
		controller2d = new MouseController2D(helix, Engine2D.Z, view2d);
		helix.addView(view2d);
		view2d.addMouseController(controller2d);
		//view2d.setTranslate(new Point3D(50, 100, 0));
		addView(view2d, c);

		c = new GridBagConstraints();
		c.gridx = 1;
		c.gridy = 1;
		c.weightx = 10;
		c.weighty = 10;
		view3d = new CurveView3D(helix, dim);
		helix.addView(view3d);
		controller3d = new ControllerMouse3D(view3d);
		view3d.addMouseKeybController(controller3d);
		addView(view3d, c);
	}

}
